Skip to content

fix(admin): refuse a write at a path above a protected value - #1353

Merged
cameri merged 1 commit into
rewrite/mainfrom
fix/1352-write-protected-parent
Dec 2, 2026
Merged

cameri merged 1 commit into
rewrite/mainfrom
fix/1352-write-protected-parent

Conversation

@chappie-daemon

Copy link
Copy Markdown
Collaborator

The settings write path checked the paths a request named and let through a write at a path that holds admin.passwordHash. Replacing admin replaced the hash, so a settings write could take over the console. Closes #1352.

Measured before

On cb22d716:

PATCH /admin/settings {"path": "admin", "value": {"passwordHash": "scrypt$probe"}}
-> 200 {"ok":true,"path":"admin","value":{"passwordHash":"***"}}
settings.yaml: scrypt:BwcHBwcH…  ->  scrypt$probe

The echo redacts the value, so the answer looks correct while the write lands. MCP settings_set calls the same patch_settings::apply, so a token holding only the write scope reached it too.

Why

patch_settings.rs:108 refused only a change whose path is write-protected. validate.rs:578 deliberately allows passwordHash as a key under admin, so the value validated, and set_by_path then replaced the subtree.

main guards this by comparing documents rather than paths: patch-settings-controller.ts:92-100 calls changedWriteProtectedSettingsPaths(protectedBefore, nextUserSettings) and refuses when any protected value moved, with a comment naming this exact case.

Change

  • collect_write_protected_settings and changed_write_protected_settings_paths in nostream-config, ported from settings-redaction.ts:56-86: every protected path in a document, and the ones whose value differs between two documents, added or removed ones included.
  • patch_settings::apply collects the protected values of the stored user document and of the document as it would be saved, after the changes are applied and before anything is written, and refuses with Path is write-protected on any difference.

Testing

Case Result
cargo test -p nostream-config --test redaction 14 passed (2 new)
cargo test -p nostream-admin --test write_path 6 passed (1 new)
Without the guard (the controller file at base, new tests kept) the new admin test fails: 200 where 400 is required
cargo fmt --check, cargo clippy -D warnings clean

The end-to-end test asserts the 400, that settings.yaml still holds the old hash, and that nothing is queued to the outbox.

`PATCH /admin/settings` and the MCP `settings_set` tool checked the paths the request
named, so a change at a path that holds `admin.passwordHash` — replacing `admin` — wrote
it too: one change with `{"path":"admin","value":{"passwordHash":"…"}}` answered 200 and
the stored hash became the one sent, and a token holding only the `write` scope could
reach it through `settings_set`.

What is protected is now read from the stored document and from the document as it would
be saved, and a write that moves one is refused with `Path is write-protected`, as the
console on `main` already does (`settings-redaction.ts:56-86`,
`patch-settings-controller.ts:92-100`). The comparison covers a value that is added or
removed as well as one that changes.

Closes #1352.
@coderabbitai

coderabbitai Bot commented Dec 2, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1580fcd5-0ae0-4f1a-ba2f-23b69c7d812e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@changeset-bot

changeset-bot Bot commented Dec 2, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6cc9a33

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@greptile-apps

greptile-apps Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5RetriggerView in Greptile

[Critical impact] The PR appears safe to merge; no actionable issues were found.

Summary

The PR blocks settings writes that change a protected value through its parent.

  • Settings writes refuse changes that replace protected values indirectly.

No actionable issues were found. Review was based on source inspection; tests were not run.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  HTTP["PATCH /admin/settings"] --> Apply["patch_settings::apply"]
  MCP["MCP settings_set"] --> Apply
  Apply --> Lock["Lock settings and check requested paths"]
  Lock --> Next["Build next_user"]
  Next --> Compare{"Protected values changed?"}
  Compare -->|Yes| Refuse["Refuse without saving or queuing"]
  Compare -->|No| Validate["Validate next_merged"]
  Validate --> Save["Save, audit, and queue settings.changed"]
Loading

Reviews (1) · Last reviewed commit: "fix(admin): refuse a write at a path abo..." · Reviewed by Greptile

@cameri
cameri merged commit 77e882a into rewrite/main Dec 2, 2026
19 checks passed
@cameri
cameri deleted the fix/1352-write-protected-parent branch December 2, 2026 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants